package AdapterAndFacade;

import AdapterAndFacade.AdapterInterfaces.Duck;
import AdapterAndFacade.AdapterInterfaces.Fly;
import AdapterAndFacade.AdapterInterfaces.Turkey;
import AdapterAndFacade.AdapterInterfacesImpl.duck.MallardDuck;
import AdapterAndFacade.AdapterInterfacesImpl.turkey.WildTurkey;
import AdapterAndFacade.Adapters.DuckAdapter;
import AdapterAndFacade.Adapters.IteratorEnumeration;
import AdapterAndFacade.Adapters.TurkeyAdapter;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试类
 * @Author: pengzx
 * @Description:
 * @Date: 16:45 2017/9/13
 * @Modified by: 1.0
 */
public class Demo {

    @Test
    public void TurkeyAdapterTest(){
        MallardDuck mallardDuck = new MallardDuck();

        WildTurkey wildTurkey = new WildTurkey();

        Duck turkeyAdapter = new TurkeyAdapter(wildTurkey);

        System.out.println("火鸡说...");
        wildTurkey.gobble();
        wildTurkey.fly();

        System.out.println("鸭子说...");
        testDuck(mallardDuck);

        System.out.println("鸭子适配器说...");
        testDuck(turkeyAdapter);
    }

    public void testDuck(Duck duck){
        duck.quack();
        duck.fly();
    }

    public void testTurkey(Turkey turkey){
        turkey.gobble();
        turkey.fly();
    }

    @Test
    public void DuckAdapterTest(){
        WildTurkey wildTurkey = new WildTurkey();

        Duck duck = new MallardDuck();

        Turkey duckAdapter = new DuckAdapter(duck);

        System.out.println("火鸡说..");
        testTurkey(wildTurkey);

        System.out.println("鸭子说...");
        duck.quack();
        duck.fly();

        System.out.println("火鸡适配器说...");
        testTurkey(duckAdapter);
    }

    @Test
    public void IteratorEnumerationTest(){
        List<Integer> list = new ArrayList<>(0);
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        IteratorEnumeration iteratorEnumeration = new IteratorEnumeration(list.iterator());
        System.out.println("IteratorEnumeration 适配器说...");
        System.out.println("iteratorEnumeration.hasMoreElements()->"+iteratorEnumeration.hasMoreElements());
        System.out.println("iteratorEnumeration.nextElement()->"+iteratorEnumeration.nextElement());
    }

}
